//
//  main.cpp
//  min-cut
//
//  Created by Emanuele Vespa on 5/7/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include "ParallelMinCut.h"


void help();



int main (int argc, const char * argv[])
{
    
   
    
    list<int> * first;
    list<int> * second;
    list<int>::iterator it;
    MultiGraph g;
    time_t start;
    time_t end;

    
    
    
   
//    g.generateMatrix(100);
//    
//    if (g.DFS()) {
//        g.saveMatrix("/Users/manu/Documents/University/University of Pisa/SPD/parallel/graph-100.txt");
//    }
//    
//    else {
//        cout << "The graph is not connected " << endl;
//        return 1;
//    }    
        
          
    g.readGraph("/Users/manu/Documents/University/University of Pisa/SPD/parallel/graph-1000.txt");
    
    if(!g.DFS()) return 0;
   
    if(argc >= 2){
        
        if( strcmp(argv[1], "--parallel") == 0 ){    
            
            if(argc == 3) {
                
                start = time(NULL);
                g.ParallelKarger(atoi(argv[2]));
                
                end = time(NULL);
                
                cout << "The Parallel algorithm finished in :  " << end - start << " seconds using " << argv[2] << " threads " << endl;
                
                
            }
            
            else {
                
                
                start = time(NULL);
                g.ParallelKarger();
                
                end = time(NULL);
                
                cout << "The Parallel algorithm finished in :  " << end - start << " seconds " << endl;
                
            }
            
            
        }
        
        
        if( strcmp(argv[1], "--sequential") == 0 ){    
            
            
            start = time(NULL);
            g.KargerMinCut();
            
            end = time(NULL);
            
            cout << "The Sequential algorithm finished in :  " << end - start << " seconds " << endl;
            
            
        }
        
    }
    else help();
    
    
    
    return 1;
}

void help(){
    
    cout << endl;
    cout << "Usage: " << endl;
    cout << "type 'run-mincut --sequential' to run the sequential version" << endl;
    cout << "type 'run-mincut --parallel' to run the parallel version" << endl;
    cout << "type 'run-mincut --parallel <num_thread>' to run in parallel and specify the number of threads" << endl;
    
    
    
}

